home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13484 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  46 lines

  1. Path: ns.mad.servicom.es!news
  2. From: ores@mad.servicom.es (Orestes Sanchez)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Casting
  5. Date: Mon, 25 Mar 1996 22:29:59 GMT
  6. Organization: SERVICOM
  7. Message-ID: <4j77ba$i5e@ns.mad.servicom.es>
  8. References: <3146DB9C.4022@cs.bham.ac.uk> <4idvk3$pc1@sam.inforamp.net>
  9. NNTP-Posting-Host: ppp_mad_61.inf.servicom.es
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. rmorin@inforamp.net (Randy Charles Morin) wrote:
  13.  
  14. >In article <3146DB9C.4022@cs.bham.ac.uk>,
  15. >   Matthew G Butler <M.G.Butler-MSCSE95@cs.bham.ac.uk> wrote:
  16. >>Can anyone tell me how to cast from one data type to another? What is
  17. >>the syntax? Do I have to cast explicitly or can I stick a casting
  18. >>function into my ADT and let the sprites sort it out.
  19.  
  20.  
  21. >I hope this is enough
  22. >Agrivar
  23.  
  24. Well, it is ok.
  25. There is another way: casting operator.
  26. Say you want to convert an X object to an int.
  27.  
  28. class X
  29. {
  30. public:
  31.     [...]
  32.     operator int();
  33. }
  34.  
  35. X x;
  36. int i;
  37.     i= (int)x;
  38.  
  39. I recomend you to read the "The Annotated C++ Reference Manual" or
  40. some other book from Bjarne Stroupstrup. If you are a beginner try
  41. better "The C++ language" book. The ARM is hard to digest.
  42.  
  43. Orestes
  44.  
  45.  
  46.